package oop.core.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPopupMenu;

import oop.core.entity.Entity;
import oop.core.entity.NPC;
import oop.core.med.InteractionMediator;

/**
 * A menu for Talk, Attack, ..etc
 * when avatar interact with an entity
 *
 */
public class NPCInteractionPopupMenu extends JPopupMenu implements ActionListener {

	private InteractionMediator interactionMediator;
	private NPC npc;

	private final String TALK = "Talk";
	private final String ATTACK = "Attack";
	private final String USE_SKILL = "Use skill";
	private final String USE_ITEM = "Use item";
	
	public NPCInteractionPopupMenu(InteractionMediator interactionMediator, NPC npc)
	{
		this.interactionMediator = interactionMediator;
		this.npc = npc;
		initialize();
	}
	
	private void initialize()
	{
		JButton talkButton = new JButton(TALK);
		JButton attackButton = new JButton(ATTACK);
		JButton useSkillButton = new JButton(USE_SKILL);
		JButton useItemButton = new JButton(USE_ITEM);

		talkButton.addActionListener(this);
		attackButton.addActionListener(this);
		useSkillButton.addActionListener(this);
		useItemButton.addActionListener(this);
		
		add(talkButton);
		add(attackButton);
		add(useSkillButton);
		add(useItemButton);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JButton button = (JButton)e.getSource();
		if(button.getText().equals(TALK))
		{
			interactionMediator.talk(npc);
		}
		else if(button.getText().equals(ATTACK))
		{
			
		}
		else if(button.getText().equals(USE_SKILL))
		{
			
		}
		else if(button.getText().equals(USE_ITEM))
		{
			
		}
		setVisible(false);
	}
}
